<%'  ------------------------------------------------------------
  '  doccontent.asp 
  '  ------------------------------------------------------------
  '  VCS INFO:
  '  
  '  $Revision:   1.12  $
  '  $Date:   05 Dec 2000 17:02:38  $
  '  $Author:   syu  $
  '  $Workfile:   doccontent.asp  $
  '  ------------------------------------------------------------
  '  All Rights Reserved.  Copyright (c) 1988-1998 FileNET Corp.
  '  ------------------------------------------------------------
  '%>
<!-- #include file="islogon.asp" -->
<%
'Panagon IDM Web application uses the Session variable LibraryLogonID to keep track of
'whether the user has logged on.
'Please see logoncall.asp to see how the Session variable LibraryLogonID is set.
LogonId = Session("LibraryLogonID")

'Create a Library object, reattach LogonID to get the SystemType and Name.
set LibraryObj = Server.CreateObject("IDMObjects.Library")
LibraryObj.LogonID = LogonID
SystemType = LibraryObj.SystemType
LibraryName = LibraryObj.Name

'Check that the document exists
DocID = Request.QueryString("DocID")
On Error Resume Next
set DocObj = LibraryObj.GetObject(Application("idmObjTypeDocument"), DocID)
i = DocObj.PageCount 'Force an error when DocObj is not found.
if Len(Err.Description) then
	Response.Expires = 0
	'Response.Status = "404 Not Found"
	Response.ContentType = "text/plain"
	Response.Write "Document not found."
	Response.End
end if

'For DS system, if CheckOut is passed in, then check out the document also.
if SystemType = Application("idmSysTypeDS") then
    Checkout = Request.QueryString("Checkout")
    if Checkout = "1" then
        set VersObj = DocObj.Version
	'
	'  This next test is due to a problem in MSIE where ActiveX controls
	'  that load in certain ways will make requests *twice*.  This causes
	'  real problems on checkout, because the first request checks out the
	'  document, and the second request gets the "this doc is already checked
	'  out error" when the control attempts to get the content of the document.
	'  The two requests can't be distinguished at the web server.  
	'
	'  So, if you have a document checked out already, we allow
	'  you to get another copy without checking it out, since there is no
	'  error on the second request, the document loads properly into the controls.
	'
	if not DocObj.GetState(Application("idmDocCanCheckin")) then
		On Error Resume Next
        	VersObj.CheckoutNoCopy
	end if
        if Len(Err.Description) then
            Response.Expires = 0
            Response.Status = "404 Not Found"
            Response.ContentType = "text/plain"
            Response.Write "Checkout failed: "
            Response.Write Err.Description
            Response.End
        end if
    end if
end if

if SystemType = Application("idmSysTypeIS") then
	'For Image Services, check that the page is within range.
	Page = Request.QueryString("StartPage")
	if Page = "" then
		Page = 1
	else
		Page = CLng(Page)
	end if
	if Page < 1 or Page > DocObj.PageCount then
		'For Document Services, defaults to 1.
		Response.Expires = 0
		'Response.Status = "404 Not Found"
		Response.ContentType = "text/plain"
		Response.Write "Page out of range (IDM Image Services)."
		Response.End
	end if
else
	Page=1
end if

'VP: fix for PWP/Banker Trust
if SystemType = Application("idmSysTypeDS") then
	Anchor = Request.QueryString("Anchor")
else
	Anchor = ""      'default??
end if

'Redirect to document content DLL to start retrieval
if Len(Anchor) > 0 then
	Response.Redirect "doccontent.dll?LibraryName=" + LibraryName + _
					  "&SystemType=" + CStr(SystemType) + _
					  "&LogonId=" + LogonId + _
					  "&DocId=" + DocID + _
					  "&Page=" + CStr(Page) + _
					  "#" + Anchor       
else
	Response.Redirect "doccontent.dll?LibraryName=" + LibraryName + _
					  "&SystemType=" + CStr(SystemType) + _
					  "&LogonId=" + LogonId + _
					  "&DocId=" + DocID + _
					  "&Page=" + CStr(Page)
end if					  
%>
